<template>
  <div>
    <div class="box" v-for="(item, i) in detailslist" :key="i">
      <div class="pic">
        <!-- 轮播图 -->
        <van-swipe :autoplay="3000" >
          <van-swipe-item  v-for="item in imgList" :key="item.id">
              <img v-lazy="item.src">
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="info">
        <div class="title">{{ item.title }}</div>
        <p>市场价：<del>￥{{item.market_price}}</del> 销售价：<span>￥{{item.sell_price}}</span></p>
        <div class="num">
          <span>购买数量：</span>
          <div><van-stepper v-model="getvalue" integer /></div>
        </div>
        <div class="btn">
          <van-button type="info">立即购买</van-button>
          <van-button type="danger" @click="addcar()">加入购物车</van-button>
        </div>
      </div>
      <div class="params">
        <div class="tt">商品参数</div>
        <div class="zz">
            <p>商品货号：{{item.goods_no}}</p>
            <p>库存情况：{{item.stock_quantity}}件</p>
            <p>上架时间：{{item.add_time}}</p>
        </div>
        <div class="btns">
          <van-button plain hairline type="primary" @click="topicpage">图文介绍</van-button>
          <van-button plain hairline type="danger">商品评论</van-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      detailslist: [],
      Goodslist:[],
      imgList:[],
      getvalue:1,
      goodsid:'',
    };
  },
  created() {
    this.getdetails();
    this.getGoodslist();
    this.getimg();
  },
  methods: {
    async getdetails() {
      const id=this.$route.query.id;
      this.goodsid=id;
      const res = await this.$http.get("/api/goods/getinfo/" + this.goodsid);
      this.detailslist = res.data.message;
    },
    async getGoodslist() {
      const res = await this.$http.get("/api/getgoods?pageindex=1");
    },
    async getimg(){
      const res = await this.$http.get('/api/getthumimages/'+this.goodsid);
      this.imgList=res.data.message;
    },
    addcar(){
      const obj={id:this.goodsid,num:this.getvalue}
      this.$store.commit('getgoods',obj);
      this.$store.commit('setnum',this.goodsid);
      this.$toast('已加入购物车');
    },
    topicpage(){
      this.$router.push('/goodstext/?id='+this.goodsid);
    }
  }
};
</script>

<style lang="less" scoped>
.box {
  text-align: left;
  padding: 10px;
  margin-bottom: 50px;
  .pic {
    height: 230px;
    border: 1px solid #ccc;
    border-radius: 3px;
    img{
        display: block;
        width:230px;
        height: 100%;
        margin: 0 auto;
    }
  }
  .info,
  .params {
    margin-top: 10px;
    padding: 15px;
    border-radius: 3px;
    border: 1px solid #ccc;
  }
}
.info p {
  font-size: 14px;
  margin-top: 15px;
  margin-bottom: 10px;
  margin-left: 10px;
  color: #8f8f94;
  span {
    font-weight: 700;
    font-size: 16px;
    color: red;
    font-style: normal;
  }
}
.num  {
  margin-left: 10px;
  div{
    width: 150px;
    display: inline-block;
    vertical-align: middle;
  }
}
.title {
  border-bottom: 1px solid #ccc;
}
.van-button {
  margin: 10px;
}
.params {
  .tt {
    font-size: 17px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ccc;
  }
  .zz {
    border-bottom: 1px solid #ccc;
    padding: 15px;
    margin-bottom: 10px;
  }
  .btns .van-button {
    height: 39px;
    line-height: 39px;
    border-radius: 5px;
    margin: 5px 0;
    width: 100%;
    font-size: 16px;
  }
}

</style>
